﻿using System;
using System.Text.RegularExpressions;

namespace MG_POS_PC.Util
{
    public class Regexlib
    {
        public static bool isValidInt(string strIn)
        {
            return Regex.IsMatch(strIn, "^[0-9]*[1-9][0-9]*$");
        }

        public static bool IsUnMinusInt(string strIn)
        {
            return Regex.IsMatch(strIn, @"\d+$");
        }

        public static bool isValidBool(string strIn)
        {
            return Regex.IsMatch(strIn, "^[0-1]*$");
        }

        public static bool isValidFloat(string strIn)
        {
            return Regex.IsMatch(strIn, @"\d{1,10}(\.\d{2})?$");
        }

        public static bool isValidEmail(string strIn)
        {
            return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
        }

        public static string MDYToDMY(String strIn)
        {
            return Regex.Replace(strIn, @"\b(?\d{1,2})/(?\d{1,2})/(?\d{2,4})\b", "${day}-${month}-${year}");
        }

        public static bool IsValidDecimal(string strIn)
        {
            return Regex.IsMatch(strIn, @"[0].\d{1,2}|[1]");
        }


        public static bool IsValidTel(string strIn)
        {
            return Regex.IsMatch(strIn, @"(\d+-)?(\d{4}-?\d{7}|\d{3}-?\d{8}|^\d{7,8})(-\d+)?");
        }


        public static bool IsValidDate(string strIn)
        {
            return Regex.IsMatch(strIn, @"^2\d{3}-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|[1-2]\d|3[0-1])(?:0?[1-9]|1\d|2[0-3]):(?:0?[1-9]|[1-5]\d):(?:0?[1-9]|[1-5]\d)$");
        }


        public static bool IsValidPostfix(string strIn)
        {
            return Regex.IsMatch(strIn, @"\.(?i:gif|jpg)$");
        }


        public static bool IsValidByte(string strIn)
        {
            return Regex.IsMatch(strIn, @"^[a-z]{4,12}$");
        }

        public static bool IsValidName(string strIn)
        {
            return Regex.IsMatch(strIn, @"[']");
        }


        public static bool IsValidIp(string strIn)
        {
            return Regex.IsMatch(strIn, @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$");
        }
    }
}
